function CustomString(target: Function) {
    target.prototype.toString = function () {
        return JSON.stringify(this)
    }
    Object.seal(target.prototype)
}

type Constructor = new (...args: any[]) => {}

function LogTime<T extends Constructor>(target: T) {
    return class extends target {
        createdTime: Date
        constructor(...args: any[]) {
            super(...args)
            this.createdTime = new Date()
        }
        getTime() {
            return `该对象的创建时间是：${this.createdTime}`
        }
    }
}

// 装饰器工厂
function LogInfo(n: number) {
    return function (target: Function) {
        target.prototype.introduce = function () {
            for (let i = 0; i < n; i++) {
                console.log(`我的名字是${this.name}，我的年龄：${this.age}`)
            }
        }
    }
}

@CustomString
@LogInfo(5)
@LogTime
class Person {
    constructor(
        public name: string,
        public age: number
    ) { }
    speak() {
        console.log('你好呀')
    }
}
interface Person {
    introduce(): void,
    getTime(): void
}

const p1 = new Person('张三', 18)
p1.speak()
console.log(p1.toString())
p1.introduce()
console.log(p1.getTime())
